Test validation for an action

This is an example of how to simply test validation when using xml validation files. The following code would test the contents of the xml file "ValidateableAction-contextName-validation.xml".

public void testActionValidation() throws ValidationException {
   DefaultActionValidatorManager validator = new DefaultActionValidatorManager();
   ValidateableAction action = new ValidateableAction();
   action.setParam(new Param());
   ... // setup the parameters you want to test

   validator.validate(action, "contextName");
   assertTrue(action.hasErrors()); // If the validation should fail
   assertFalse(action.hasErrors()); // If the validation should pass
   // action.getActionErrors() will give you the errors that occurred
}